package com.myhome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myhome.domain.WebConfig;
import com.myhome.mapper.WebConfigMapper;
import com.myhome.service.WebConfigService;
import org.springframework.util.StringUtils;

import java.util.List;

/**
*@Author QYiXin 
* @Date 2021 10 09 12 58
**/
@Service
public class WebConfigServiceImpl extends ServiceImpl<WebConfigMapper, WebConfig> implements WebConfigService{

    @Override
    public Page<WebConfig> findByPage(Page<WebConfig> page, String name, String type) {
        Page<WebConfig> result = this.page(page, new LambdaQueryWrapper<WebConfig>()
                                    .like(!StringUtils.isEmpty(name), WebConfig::getName, name)
                                    .eq(!StringUtils.isEmpty(type), WebConfig::getType, type));
        return result;
    }

    @Override
    public List<WebConfig> getAllBanners() {
        return this.list(new LambdaQueryWrapper<WebConfig>().eq(WebConfig::getStatus, (byte) 1).eq(WebConfig::getType, "WEB_BANNER").orderByAsc(WebConfig::getSort));
    }

}
